package fr.afcepf.vod.dao;

import java.util.Date;
import java.util.List;

import javax.inject.Named;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.springframework.transaction.annotation.Transactional;

import fr.afcepf.vod.entities.Tarifvideounite;
@Named
@Transactional
public class DaoTarifImpl implements IDaoTarif{
	
	@PersistenceContext
	private EntityManager em;
	
	@Override
	public List<Tarifvideounite> getListeTarifsValides(Date debutDispoVideo, Date finDispoVideo) {

		Query query = em.createQuery("from Tarifvideounite t where t.debutValiditeTarif < :debutVideo and t.finValiditeTarif > :finVideo");
		query.setParameter("debutVideo", debutDispoVideo);
		query.setParameter("finVideo", finDispoVideo);
		return query.getResultList();
	}

	@Override
	public Tarifvideounite getTarifById(int id) {
		return em.find(Tarifvideounite.class, id);
	}

	@Override
	public void ajouterTarif(Tarifvideounite tarif) {
		em.persist(tarif);
		
	}

}
